namespace SimpleWebServices.Web
{
    using System;
    using System.Net;
    using System.Web;
    using System.Xml;
    using SimpleWebServices;
    using SimpleWebServices.Configuration;
    using SimpleWebServices.Globalization;
    using Xunit;

    public sealed class DefaultResourceFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<DefaultResource>()
                .DerivesFrom<Resource>()
                .IsConcreteClass()
                .IsSealed()
                .HasDefaultConstructor()
                .Implements<IResource>()
                .XmlRoot("resource")
                .Result);
        }

        [Fact]
        public void ctor()
        {
            Assert.NotNull(new DefaultResource());
        }

        [Fact]
        public void op_CopyTo_IResource()
        {
            try
            {
                Default.Register<DefaultResource>(
                    "<resource" +
                    " description='This is a resource.'" +
                    " location='http://example.com/resource'" +
                    " title='Resource Title'>" +
                        "<data>" +
                            "<value name='foo'>bar</value>" +
                        "</data>" +
                        "<links>" +
                            "<link rel='canonical' href='http://example.com/resource.en.html' />" +
                        "</links>" +
                        "<metadata>" +
                            "<meta name='DC.date' content='2009-08-01' scheme='W3CDTF' />" +
                        "</metadata>" +
                    "</resource>");

                IResource actual = new TestResource();

                DefaultResource.CopyTo(actual);

                Assert.Equal<string>("This is a resource.", actual.Description);
                Assert.Equal<string>("Resource Title", actual.Title);
                Assert.Equal<string>("bar", actual.Data["foo"]);
                Assert.Equal<string>("http://example.com/resource.en.html", actual.Links["canonical"].Hyperlink.AbsoluteUri);
                Assert.Equal<string>("2009-08-01", actual.Metadata["DC.date"].Content);
            }
            finally
            {
                Default.Reset();
            }
        }

        [Fact]
        public void op_CopyTo_IResourceNull()
        {
            Assert.Throws<ArgumentNullException>(() => DefaultResource.CopyTo(null as IResource));
        }
    }
}